home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-22 | 3.2 KB | 148 lines | [TEXT/CWIE] |
- UNIT IconButtons;
- INTERFACE
-
- USES
- Types, Events, Icons, QuickDraw, Memory, IconCache;
-
- TYPE
- IconButton = RECORD
- position: Point;
- bodyIcon: INTEGER;
- hilitedBodyIcon: INTEGER;
- faceIcon: INTEGER;
- END;
- IconButtonPtr = ^IconButton;
- IconButtonHandle = ^IconButtonPtr;
-
- IdleProc = PROCEDURE;
-
- FUNCTION NewIconButton(h, v, bodyIcon, pressedBodyIcon, faceIcon: INTEGER): IconButtonHandle;
- PROCEDURE DisposeIconButton(button: IconButtonHandle);
-
- FUNCTION HitIconButton(button: IconButtonHandle; pt: Point): BOOLEAN;
- FUNCTION TrackIconButton(button: IconButtonHandle; idle: IdleProc): BOOLEAN;
-
- PROCEDURE DrawIconButton(button: IconButtonHandle);
-
- IMPLEMENTATION
-
- USES
- Events;
-
- PROCEDURE DrawIconButton(button: IconButtonHandle);
- VAR
- icon: CIconHandle;
- box: Rect;
-
- BEGIN
- icon := GetCachedIcon(button^^.bodyIcon);
- IF icon <> NIL THEN
- BEGIN
- box := icon^^.iconPMap.bounds;
- OffsetRect(box, button^^.position.h, button^^.position.v);
-
- PlotCachedIcon(button^^.bodyIcon, box);
- PlotCachedIcon(button^^.faceIcon, box);
- END;
- END;
-
- FUNCTION TrackIconButton(btn: IconButtonHandle; idle: IdleProc): BOOLEAN;
- VAR
- pt: Point;
- pressed: BOOLEAN;
- box: Rect;
- face, down, body: CIconHandle;
-
- BEGIN
- face := GetCachedIcon(btn^^.faceIcon);
- down := GetCachedIcon(btn^^.hilitedBodyIcon);
- body := GetCachedIcon(btn^^.bodyIcon);
-
- IF (face = NIL) OR (down = NIL) OR (body = NIL) THEN
- BEGIN
- DebugStr('TrackIconButton: GetCachedIcon');
- TrackIconButton := FALSE;
- Exit(TrackIconButton);
- END;
-
- box := body^^.iconPMap.bounds;
- OffsetRect(box, btn^^.position.h, btn^^.position.v);
-
- pressed := FALSE;
- WHILE Button DO
- BEGIN
- GetMouse(pt);
- IF idle <> NIL THEN
- idle;
-
- IF PtInRect(pt, box) AND (NOT pressed) THEN
- BEGIN
- pressed := TRUE;
- PlotCIcon(box, down);
- OffsetRect(box, 1, 1);
- PlotCIcon(box, face);
- OffsetRect(box, -1, -1);
- END;
-
- IF NOT PtInRect(pt, box) AND pressed THEN
- BEGIN
- pressed := FALSE;
- PlotCIcon(box, body);
- PlotCIcon(box, face);
- END;
- END;
-
- IF pressed THEN
- BEGIN
- PlotCIcon(box, body);
- PlotCIcon(box, face);
- END;
-
- TrackIconButton := pressed;
- END;
-
- FUNCTION HitIconButton(button: IconButtonHandle; pt: Point): BOOLEAN;
- VAR
- body: CIconHandle;
- box: Rect;
-
- BEGIN
- body := GetCachedIcon(button^^.bodyIcon);
- IF body = NIL THEN
- BEGIN
- DebugStr('HitIconButton: GetCachedIcon');
- HitIconButton := FALSE;
- Exit(HitIconButton);
- END;
-
- box := body^^.iconPMap.bounds;
- OffsetRect(box, button^^.position.h, button^^.position.v);
-
- HitIconButton := PtInRect(pt, box);
- END;
-
- FUNCTION NewIconButton(h, v, bodyIcon, pressedBodyIcon, faceIcon: INTEGER): IconButtonHandle;
- VAR
- button: IconButtonHandle;
-
- BEGIN
- Handle(button) := NewHandleClear(SizeOf(IconButton));
- IF button <> NIL THEN
- BEGIN
- button^^.position.h := h;
- button^^.position.v := v;
- button^^.bodyIcon := bodyIcon;
- button^^.hilitedBodyIcon := pressedBodyIcon;
- button^^.faceIcon := faceIcon;
- END;
-
- NewIconButton := button;
- END;
-
- PROCEDURE DisposeIconButton(button: IconButtonHandle);
- BEGIN
- IF button <> NIL THEN
- DisposeHandle(Handle(button));
- END;
-
- END.